Let f: DR be a function defined on a subset D of the real line R. Let I = [a, b] be a closed interval contained in D, and let P = {[x0, x1), [x1, x2), ... [xn-1, xn]} be a of partition of I, where a = x0 < x1 < x2 ... < xn = b.
The Riemann sum of f over I with partition P is defined as
S = sum_{i=1}^{n} f(y_i)(x_{i}-x_{i-1})
S = sum_{i=1}^{n} f(y_i)(x_{i}-x_{i-1})

where xi-1 ≤ yixi. The choice of yi in this interval is arbitrary. If yi = xi-1 for all i, then S is called a left Riemann sum. If yi = xi, then S is called a right Riemann sum. If yi = (xi+xi-1)/2, then S is called a middle Riemann sum. The average of the left and right Riemann sum is the trapezoidal sum.


The interval for a Reimann sum can be found using x= (b-a)/ n where n= the number of rectangles needed.